import { STORAGE_SETTING_KEY } from '@/common/constance';
import { DefaultPrinterConfig } from '@/type';

export const getDefaultSetting = (): DefaultPrinterConfig => {
    const defaultSetting = localStorage.getItem(STORAGE_SETTING_KEY);
    if (!defaultSetting)
        return {
            defaultPrint: null,
            defaultCache: 1
        };
    return JSON.parse(defaultSetting);
};

export const setDefaultSetting = (option: DefaultPrinterConfig) => {
    localStorage.setItem(
        STORAGE_SETTING_KEY,
        JSON.stringify({
            defaultPrint: option.defaultPrint,
            defaultCache: option.defaultCache
        })
    );
};
